<?php

class youtube extends stwidgets {

    function youtube() {
        $this->WP_Widget(false, $name = 'ST YouTube');
    }

    function widget($args, $instance) {
        $yt_video_link = $instance['yt_video_link'];
        $widget_text = $instance['widget_text'];
        $yt_width = $instance['yt_width'];
        $yt_height = $instance['yt_height'];
        $yt_show = $instance['yt_show'];

        if (substr($yt_video_link, 0, 31) == 'http://www.youtube.com/watch?v=') {

            $id = substr($yt_video_link, strpos($yt_video_link, "?v=") + 3);
        } else if (substr($yt_video_link, 0, 15) == 'http://youtu.be') {

            $id = substr($yt_video_link, strripos($yt_video_link, "/") + 1);
        } else {
            $id = $yt_video_link;
        }
        ?>
        <!--div class="cleaner_h10">&nbsp;</div-->
        <div class="videowidget">
            <div class="mh"> 
                <span class="top_arrow"></span>
                <div class="ml">
                    <?php if ($widget_text != '') { ?>

                        <h1><?php echo $widget_text ?></h1>

                    <?php } ?>
                </div> 
                 </div>
                <object width="<?php echo $yt_width ?>" height="<?php echo $yt_height; ?>">
                    <param name="movie" value="http://www.youtube.com/v/<?php echo $id; ?>" />
                    <param name="wmode" value="transparent" />
                    <embed src="http://www.youtube.com/v/<?php echo $id; ?>"
                           type="application/x-shockwave-flash"
                           wmode="transparent" width="<?php echo $yt_width ?>" height="<?php echo $yt_height; ?>" />
                </object>

                <!--div class="cleaner_h10">&nbsp;</div-->
           
        </div>

                <?php
            }

            function form($instance) {
                ?>
                <p>
                    <label for="">Text</label>
                    <input type="text" name="widget_text" class="widefat" value="<?php echo $instance['widget_text'] ?>">
                </p>
                <p>
                    <label for="">Video link</label>
                    <input type="text" name="yt_video_link" class=" widefat check_yt_link"  value="<?php echo $instance['yt_video_link'] ?>">
                </p>
                <p
                    <label for="">Width</label>
                    <input type="text" name="yt_width" class="widefat" value="<?php echo $instance['yt_width'] ?>">
                </p>
                <p
                    <label for="">Height</label>
                    <input type="text" name="yt_height" class="widefat" value="<?php echo $instance['yt_height'] ?>">
                </p>
               

        <?php
    }

}